package nero.yncc.com.createart.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

import nero.yncc.com.createart.R;
import nero.yncc.com.createart.bean.GodBean;
import nero.yncc.com.createart.interfaces.InterfaceDoSomeThing;
import nero.yncc.com.createart.utils.MyLayoutManager;

/**
 * Created by nero on 17-6-27.
 */

public class AdapterGoodsSpec extends RecyclerView.Adapter<AdapterGoodsSpec.Holder> {

    Context context;
    ArrayList<GodBean.SpecAttr> arrayList;
    InterfaceDoSomeThing interfaceDoSomeThingNoArg;

    public AdapterGoodsSpec(Context context, ArrayList<GodBean.SpecAttr> arrayList, InterfaceDoSomeThing interfaceDoSomeThingNoArg) {
        this.context = context;
        this.arrayList = arrayList;
        this.interfaceDoSomeThingNoArg = interfaceDoSomeThingNoArg;
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        View  view = LayoutInflater.from(context).inflate(R.layout.adapter_detail_in, null);
        Holder holer = new Holder(view);
        return holer;
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        GodBean.SpecAttr bean = arrayList.get(position);
        holder.tv_content.setText(bean.getName());
        AdapterGoodsSpecIn adapterDetailInandIn = new AdapterGoodsSpecIn(context, bean.getList(),interfaceDoSomeThingNoArg, bean);
        holder.rc_list.setLayoutManager(new MyLayoutManager(context));
        holder.rc_list.setAdapter(adapterDetailInandIn);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView tv_content;
        RecyclerView rc_list;

        public Holder(View itemView) {
            super(itemView);
            tv_content = itemView.findViewById(R.id.tv_content);
            rc_list = itemView.findViewById(R.id.rc_list);
        }
    }
}
